//
//  JZViewController.m
//  JZAdSDK
//
//  Created by 二跳 on 09/28/2025.
//  Copyright (c) 2025 二跳. All rights reserved.
//

#import "JZViewController.h"
#import <JZAdSDK/JZAdSDKNativeAd.h>
#import <JZAdSDK/JZAdSDKNativeExpressAd.h>
#import <JZAdSDK/JZAdSDKSplashAd.h>
#import <JZAdSDK/JZAdSDKInterstitialAd.h>
#import <JZAdSDK/JZAdSDKServiceAdView.h>
#import <JZAdSDK/JZAdSDKBannerAdView.h>
#import <JZAdSDK/JZAdSDKRewardVideoAd.h>

@interface JZViewController ()<JZAdSDKNativeExpressAdDelegate,JZAdSDKInterstitialAdDelegate,JZAdSDKBannerAdViewDelegate,JZAdSDKRewardVideoAdDelegate,JZAdSDKServiceAdViewDelegate>

@property(nonatomic, strong)JZAdSDKNativeExpressAd *nativeExpressAd;

@property (nonatomic, strong) JZAdSDKInterstitialAd *interstitialAd;

@property (nonatomic, strong) JZAdSDKBannerAdView *bannerView;

@property (nonatomic, strong) JZAdSDKRewardVideoAd *rewardVideoAd;

@property (nonatomic, strong) JZAdSDKServiceAdView *serviceAdView;

@end

@implementation JZViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

#pragma mark - 服务广告
- (void)loadServiceAdView{
    self.serviceAdView = [[JZAdSDKServiceAdView alloc]initWithFrame:CGRectMake(0, 200, 50, 50)];
    self.serviceAdView.delegate = self;
    self.serviceAdView.controller = self;
    self.serviceAdView.posId = @"";
    // 设置展示关闭按钮
    self.serviceAdView.showCloseView = YES;
    [self.serviceAdView loadAndShow];
}

#pragma mark - JZAdSDKServiceAdViewDelegate
/**
 广告获取成功
 
 @param serviceAdView banner实例
 */
- (void)JZ_serviceAdViewDidReceived:(JZAdSDKServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告拉取失败
 
 @param serviceAdView banner实例
 @param error 错误描述
 */
- (void)JZ_serviceAdViewFailToReceived:(JZAdSDKServiceAdView *)serviceAdView error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 广告点击
 
 @param serviceAdView 广告实例
 @param loadingPageURL 广告落地页地址，当渠道为bwt，并且customLoadingPage为YES时有值
 */
- (void)JZ_serviceAdViewClicked:(JZAdSDKServiceAdView *)serviceAdView loadingPageURL:(NSString *)loadingPageURL{
    NSLog(@"%s", __func__);
}

/**
 广告关闭
 
 @param serviceAdView 广告实例
 */
- (void)JZ_serviceAdViewClose:(JZAdSDKServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告展示
 
 @param serviceAdView 广告实例
 */
- (void)JZ_serviceAdViewExposure:(JZAdSDKServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告展示上报
 
 @param serviceAdView 广告实例
 */
- (void)JZ_serviceAdViewExposureReport:(JZAdSDKServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 广告点击上报
 
 @param serviceAdView 广告实例
 */
- (void)JZ_serviceAdViewClickedReport:(JZAdSDKServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

/**
 关闭落地页
 
 @param serviceAdView 广告实例
 */
- (void)JZ_serviceAdViewCloseLandingPage:(JZAdSDKServiceAdView *)serviceAdView{
    NSLog(@"%s", __func__);
}

#pragma mark - 激励视频广告
- (void)loadRewardVideo{
    self.rewardVideoAd = [[JZAdSDKRewardVideoAd alloc]init];
    self.rewardVideoAd.delegate = self;
    self.rewardVideoAd.controller = self;
    self.rewardVideoAd.posId = @"23636003";
    self.rewardVideoAd.videoMuted = YES;
    [self.rewardVideoAd loadRewardVideoAd];
}

#pragma mark - JZAdSDKRewardVideoAdDelegate
/**
 广告数据加载成功回调

 @param rewardedVideoAd JZAdSDKRewardVideoAd 实例
 */
- (void)JZ_rewardVideoAdDidLoad:(JZAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
    // 价格上报
//    NSInteger price = [self.rewardVideoAd getBidPrice];
//    [self.rewardVideoAd sendWinNotice:price];
    [self.rewardVideoAd showRewardVideoAdFromRootViewController:self];
}

/**
 视频播放页即将展示回调

 @param rewardedVideoAd JZAdSDKRewardVideoAd 实例
 */
- (void)JZ_rewardVideoAdWillVisible:(JZAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告曝光回调

 @param rewardedVideoAd JZAdSDKRewardVideoAd 实例
 */
- (void)JZ_rewardVideoAdDidExposed:(JZAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告曝光上报回调（只会回调一次）

 @param rewardedVideoAd JZAdSDKRewardVideoAd 实例
 */
- (void)JZ_rewardVideoAdDidExposeReport:(JZAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频播放页关闭回调

 @param rewardedVideoAd JZAdSDKRewardVideoAd 实例
 */
- (void)JZ_rewardVideoAdDidClose:(JZAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告信息点击回调（可能回调多次）

 @param rewardedVideoAd JZAdSDKRewardVideoAd 实例
 */
- (void)JZ_rewardVideoAdDidClicked:(JZAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告信息点击上报回调（只会回调一次）

 @param rewardedVideoAd JZAdSDKRewardVideoAd 实例
 */
- (void)JZ_rewardVideoAdDidClickReport:(JZAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告各种错误信息回调

 @param rewardedVideoAd JZAdSDKRewardVideoAd 实例
 @param error 具体错误信息
 */
- (void)JZ_rewardVideoAd:(JZAdSDKRewardVideoAd *)rewardedVideoAd didFailWithError:(NSError *)error{
    NSLog(@"%s", __func__);
}


/**
 视频广告播放达到激励条件回调

 @param rewardedVideoAd JZAdSDKRewardVideoAd 实例
 */
- (void)JZ_rewardVideoAdDidRewardEffective:(JZAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

/**
 视频广告视频播放完成

 @param rewardedVideoAd JZAdSDKRewardVideoAd 实例
 */
- (void)JZ_rewardVideoAdDidPlayFinish:(JZAdSDKRewardVideoAd *)rewardedVideoAd{
    NSLog(@"%s", __func__);
}

#pragma mark - banner广告
- (void)loadBanner{
    CGFloat width = self.view.frame.size.width;
    CGFloat height = width * 5 / 32;
    self.bannerView = [[JZAdSDKBannerAdView alloc]initWithFrame:CGRectMake(0, 200, width, height)];
    self.bannerView.delegate = self;
    self.bannerView.controller = self;
    self.bannerView.posId = @"";
    // 设置展示关闭按钮
    self.bannerView.showCloseView = YES;
    [self.bannerView loadAndShow];
}

#pragma mark - JZAdSDKBannerAdViewDelegate
/**
 广告获取成功
 
 @param bannerAdView banner实例
 */
- (void)JZ_bannerAdViewDidReceived:(JZAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
    // 价格上报
//    NSInteger price = [self.bannerView getBidPrice];
//    [self.bannerView sendWinNotice:price];
}

/**
 广告拉取失败
 
 @param bannerAdView banner实例
 @param error 错误描述
 */
- (void)JZ_bannerAdViewFailToReceived:(JZAdSDKBannerAdView *)bannerAdView error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 广告点击
 
 @param bannerAdView 广告实例
 */
- (void)JZ_bannerAdViewClicked:(JZAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 广告关闭
 
 @param bannerAdView 广告实例
 */
- (void)JZ_bannerAdViewClose:(JZAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 广告展示
 
 @param bannerAdView 广告实例
 */
- (void)JZ_bannerAdViewExposure:(JZAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 广告展示上报
 
 @param bannerAdView 广告实例
 */
- (void)JZ_bannerAdViewExposureReport:(JZAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 广告点击上报
 
 @param bannerAdView 广告实例
 */
- (void)JZ_bannerAdViewClickedReport:(JZAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

/**
 关闭落地页
 
 @param bannerAdView 广告实例
 */
- (void)JZ_bannerAdViewCloseLandingPage:(JZAdSDKBannerAdView *)bannerAdView{
    NSLog(@"%s", __func__);
}

#pragma mark - 插屏广告
- (void)loadInterstitialAd {
    self.interstitialAd = [[JZAdSDKInterstitialAd alloc]init];
    self.interstitialAd.delegate = self;
    self.interstitialAd.controller = self;
    self.interstitialAd.posId = @"13945365";
    [self.interstitialAd loadInterstitialAd];
}

#pragma mark - JZAdSDKInterstitialAdDelegate
/**
 JZAdSDKInterstitialAd请求成功回调
 
 @param interstitialAd 插屏广告实例对象
*/
- (void)JZ_interstitialAdSuccedToLoad:(JZAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
    // 获取价格，价格上报
//    NSInteger price = [self.interstitialAd getBidPrice];
//    [self.interstitialAd sendWinNotice:price];
    // 设置控制器，展示插屏广告
    self.interstitialAd.controller = self;
    [self.interstitialAd showInterstitialAd];
}

/**
 JZAdSDKInterstitialAd请求失败回调

 @param interstitialAd 插屏广告实例对象
 @param error 失败原因
*/
- (void)JZ_interstitialAdFailedToLoad:(JZAdSDKInterstitialAd *)interstitialAd error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 JZAdSDKInterstitialAd展示在屏幕内回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)JZ_interstitialAdDidPresent:(JZAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 JZAdSDKInterstitialAd展示在屏幕内失败回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)JZ_interstitialAdFailedToPresent:(JZAdSDKInterstitialAd *)interstitialAd error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 JZAdSDKInterstitialAd点击回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)JZ_interstitialAdDidClick:(JZAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 JZAdSDKInterstitialAd关闭回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)JZ_interstitialAdDidClose:(JZAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 JZAdSDKInterstitialAd展示回调
 
 @param interstitialAd 广告实例
 */
- (void)JZ_interstitialAdExposure:(JZAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 JZAdSDKInterstitialAd展示上报回调
 
 @param interstitialAd 广告实例
 */
- (void)JZ_interstitialAdExposureReport:(JZAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}


/**
 JZAdSDKInterstitialAd点击上报回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)JZ_interstitialAdDidClickReport:(JZAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}

/**
 JZAdSDKInterstitialAd关闭落地页回调
 
 @param interstitialAd 广告实例
 */
- (void)JZ_interstitialAdCloseLandingPage:(JZAdSDKInterstitialAd *)interstitialAd{
    NSLog(@"%s", __func__);
}
#pragma mark - 信息流模板广告

- (void)loadNativeExpress {
    CGFloat width = self.view.frame.size.width;
    self.nativeExpressAd = [[JZAdSDKNativeExpressAd alloc]initWithAdSize:CGSizeMake(width, 50)];
    self.nativeExpressAd.posId = @"99908725";
    self.nativeExpressAd.delegate = self;
    self.nativeExpressAd.expressType = JZNativeExpressTypeImage;
    self.nativeExpressAd.controller = self;
    [self.nativeExpressAd loadNativeExpressAd:1];
}

#pragma mark - JZAdSDKNativeExpressAdDelegate
/**
 信息流模版广告请求成功
 
 @param nativeExpressAd 广告实例
 @param adViewArray 广告模板集合
 */
- (void)JZ_nativeExpressAdSucessToLoad:(JZAdSDKNativeExpressAd *)nativeExpressAd
                     adViewArray:(NSArray<__kindof UIView<JZAdSDKNativeExpressAdViewDelegate> *> *)adViewArray{
    NSLog(@"%s", __func__);
    UIView<JZAdSDKNativeExpressAdViewDelegate> *adView = [adViewArray firstObject];
    [adView render];
    [self.view addSubview:adView];
    CGSize adViewSize = adView.frame.size;
    adView.frame = CGRectMake(0, 200, adViewSize.width, adViewSize.height);
}

/**
 信息流模版广告请求失败
 
 @param nativeExpressAd 广告实例
 @param error 请求错误描述
 */
- (void)JZ_nativeExpressAdFailToLoad:(JZAdSDKNativeExpressAd *)nativeExpressAd
                         error:(NSError *)error{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告渲染成功
 
 @param adView 广告视图
 */
- (void)JZ_nativeExpressAdViewRenderOrRegistSuccess:(UIView<JZAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告渲染失败
 
 @param adView 广告视图
 */
- (void)JZ_nativeExpressAdViewRenderOrRegistFail:(UIView<JZAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告被点击
 
 @param nativeExpressAd 广告模板
 */
- (void)JZ_nativeExpressAdClicked:(JZAdSDKNativeExpressAd *)nativeExpressAd
                     adView:(__kindof UIView<JZAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告被关闭
 
 @param nativeExpressAd 广告模板
 */
- (void)JZ_nativeExpressAdClose:(JZAdSDKNativeExpressAd *)nativeExpressAd
                   adView:(__kindof UIView<JZAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告被展示
 
 @param nativeExpressAd 广告实例
 */
- (void)JZ_nativeExpressAdExposure:(JZAdSDKNativeExpressAd *)nativeExpressAd
                      adView:(__kindof UIView<JZAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告展示上报
 
 @param nativeExpressAd 广告实例
 */
- (void)JZ_nativeExpressAdExposureReport:(JZAdSDKNativeExpressAd *)nativeExpressAd
                            adView:(__kindof UIView<JZAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告点击上报
 
 @param nativeExpressAd 广告模板
 */
- (void)JZ_nativeExpressAdClickedReport:(JZAdSDKNativeExpressAd *)nativeExpressAd
                           adView:(__kindof UIView<JZAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

/**
 信息流模版广告落地页被关闭
 
 @param nativeExpressAd 广告实例
 */
- (void)JZ_nativeExpressAdCloseLandingPage:(JZAdSDKNativeExpressAd *)nativeExpressAd
                              adView:(__kindof UIView<JZAdSDKNativeExpressAdViewDelegate> *)adView{
    NSLog(@"%s", __func__);
}

@end
